package com.mrzhou.study.config;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;

@Configuration
public class StudyConfiguration {

//    @Primary
//    @Bean
//    public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
//        builder.simpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
//        objectMapper.setLocale(Locale.CHINA);
//        objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
//        objectMapper.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
//        objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA));
//        objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
//        objectMapper.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true);
//        objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
//        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//        objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
//        objectMapper.setSerializerFactory(objectMapper.getSerializerFactory().withSerializerModifier(new ))
//        objectMapper.getDeserializationConfig().withoutFeatures(new DeserializationFeature[]{DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES});
//        objectMapper.findAndRegisterModules();
//        return objectMapper;
//    }

//    @Bean
//    public void fileConfig() throws Exception {
//        String filePath = System.getProperty("config.file.path"); // 在启动时设置参数来读取磁盘上的文件, 示例: -Dconfig.file.path=C:\Users\EDZ\Desktop\temp.json
//        if(StringUtils.isBlank(filePath)) {
//            throw new RuntimeException("config.file.path 参数不可少！");
//        }
//        BufferedReader br = new BufferedReader(new FileReader(new File(filePath)));
//        StringBuffer sb = new StringBuffer();
//        String temp = br.readLine();
//        while(temp != null) {
//            sb.append(temp);
//            temp = br.readLine();
//        }
//        System.out.println(sb.toString());
//    }

}
